import { Component, Injector, ViewEncapsulation, ViewChild, ElementRef } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { PipelineListDto, OrganizationUnitServiceProxy, ComboboxItemDto } from '@shared/service-proxies/service-proxies';
import { PipelineNodesServiceProxy} from '@shared/service-proxies/service-proxies';
import { finalize } from 'rxjs/operators';
import { appModuleAnimation } from '@shared/animations/routerTransition';

@Component({
  selector: 'zl1',
  templateUrl: './zl1.component.html',
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]
})

export class ZL1ModalComponent extends AppComponentBase {

  saving = false;

  pipe: PipelineListDto = new PipelineListDto();

  zhiKongKaNo = '';

  constructor(
    injector: Injector,
    private _organizationUnitServiceProxy: OrganizationUnitServiceProxy,
    private _taskServiceProxy: PipelineNodesServiceProxy
  ) {
    super(injector);
  }


  load(pipe: PipelineListDto): void {
    this.pipe = pipe;

    this._taskServiceProxy.getZhiKongKaNo(pipe.id)
    .subscribe((result) => {
      this.zhiKongKaNo = typeof result === 'object' ? '' : result;
    });

  }


  save(): void {
    this.saving = true;

    this._taskServiceProxy.setZhiKongKaNo(this.pipe.id, this.zhiKongKaNo)
      .pipe(finalize(() => { this.saving = false; }))
      .subscribe(result => {
        this.notify.success('记录质控卡成功');
      });
  }

}
